chore: add OHLCVService for real-time candlestick WebSocket streaming#8695
Conversation
2d69c0f to
bd0d4d2
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
| */ | ||
| async subscribe(options: OHLCVSubscriptionOptions): Promise<void> { | ||
| const channel = this.#buildChannel(options); | ||
| return this.#withChannelLock(channel, () => this.#subscribeInner(channel)); |
There was a problem hiding this comment.
I think you can use import { Mutex } from 'async-mutex'; its already used in other Controllers
|
@metamaskbot publish-preview |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 337abd9. Configure here.
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Kriys94
left a comment
There was a problem hiding this comment.
LGTM. Thanks a lot @sahar-fehri

Explanation
Architecture Overview
What
OHLCVServicefor real-time OHLCV (candlestick) data streaming via the backend WebSocket gatewayBackendWebSocketService,AccountActivityService) into a newsrc/ws/directory per code review feedbackWhy
ws/folder for better discoverabilityNew files
src/ws/ohlcv/OHLCVService.ts— main service with subscribe/unsubscribe semantics, reference counting, grace-period unsubscribe, idempotency checks, chain-status forwarding, and automatic resubscription on reconnectsrc/ws/ohlcv/OHLCVService.test.ts— 22 unit tests covering all paths (100% branch coverage)src/ws/ohlcv/OHLCVService-method-action-types.ts— auto-generated messenger action typessrc/ws/ohlcv/types.ts—OHLCVBarandOHLCVSubscriptionOptionstypessrc/ws/ohlcv/index.ts— barrel exportsModified files
src/index.ts— added exports forOHLCVService, its types, and allowed actions/events; updated import paths to./ws/eslint-suppressions.json— updated paths for moved files, added suppressions for new test fileCHANGELOG.md— documented new service and exportsMoved files (no logic changes)
src/BackendWebSocketService.ts→src/ws/BackendWebSocketService.tssrc/BackendWebSocketService.test.ts→src/ws/BackendWebSocketService.test.tssrc/BackendWebSocketService-method-action-types.ts→src/ws/BackendWebSocketService-method-action-types.tssrc/AccountActivityService.ts→src/ws/AccountActivityService.tssrc/AccountActivityService.test.ts→src/ws/AccountActivityService.test.tssrc/AccountActivityService-method-action-types.ts→src/ws/AccountActivityService-method-action-types.ts./logger→../logger,./types→../types, test helper paths)Key design decisions
AccountActivityService(auto-subscribes on account change),OHLCVServiceexposessubscribe()/unsubscribe()called by the UI when the chart mounts/unmountschannelHasSubscriptionbefore subscribing; duplicate calls are no-ops (React Strict Mode safe)system-notifications.v1.market-data.v1(auto-subscribed by server) and publishesOHLCVService:chainStatusChangedchainStatusChanged { status: 'down' }for all tracked chains, triggering UI polling fallbacksessionIdneeded for OHLCV; UI polling fallback covers the gap)init()method — system notification callback registered ininit()(not constructor) to comply with messenger-in-constructor lint ruleEvents published
OHLCVService:barUpdated—{ channel, bar: OHLCVBar }— new candle data from WebSocketOHLCVService:chainStatusChanged—{ chainIds, status, timestamp? }— chain up/down (server notification or WS disconnect)OHLCVService:subscriptionError—{ channel, error, operation }— subscribe or unsubscribe failureReferences
Checklist
Note
Medium Risk
Adds a new WebSocket-driven market-data service with reference counting, timers, and reconnect resubscription logic, which can affect subscription lifecycles and event delivery. Also moves existing WebSocket services into
src/ws/, so consumers relying on internal paths (vs package exports) could break if any remain.Overview
Adds a new
OHLCVServiceto stream real-time OHLCV bars over WebSocket, exposingsubscribe/unsubscribevia messenger actions, publishingbarUpdated/chainStatusChanged/subscriptionErrorevents, and handling reconnect resubscription with ref-counting plus a grace-period unsubscribe (mutex-protected).Refactors
core-backendby movingBackendWebSocketServiceandAccountActivityService(and their tests/action-type files) intosrc/ws/, updating imports/exports (src/index.ts), and updating lint suppressions; also addsasync-mutexplus comprehensive unit tests for the new service and documents the addition in the changelog.Reviewed by Cursor Bugbot for commit 730af62. Bugbot is set up for automated code reviews on this repo. Configure here.